
public class sort {

	
	public static void main(String[] args) {
		int[] arr = {4,2,6,1,7,3,5,9,2};
		int temp;
		int min = 1000000;
		int max = -1000000;
		

		for (int i = 0; i < arr.length-i; i++) {
			min = arr[i];
			max = arr[arr.length-1];
			for (int j = i; j < arr.length; j++) {
				if(arr[j] < min){
					temp = min;
					min=arr[j];
					arr[j]=temp;
					arr[i]=min;
				}
				if(arr[j] > max){
					temp = max;
					max=arr[j];
					arr[j]=temp;
					arr[i]=max;
				}
			}
		}
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i]+" ");
		}

	}

}
